package com.example.mapper;


import com.example.pojo.VerifyResult;
import com.example.pojo.VerifyResultImg;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface VerifyMapper {

    // 查询所有验证结果
    @Select("select * from verifyresult")
    public List<VerifyResult> findAll();

    //倒序查询所有验证结果
    @Select("select * from verifyresult order by ID desc")
    public List<VerifyResult> findAllF();

    //获取最新的验证结果
    @Select("select * from verifyresult order by ID desc limit 1")
    public VerifyResult findNewest();

    //根据verifyresult表的id从verifyresultimg表中查询与verifyresultid相同的数据
    @Select("select * from verifyresultimg where VerifyResultID = #{ID}")
    public List<VerifyResultImg> findByVerifyResultID(Integer ID);

    //添加验证结果
    @Select("insert into verifyresult (machineID,shiftName,successRate,verifyTime) values (#{machineID},#{shiftName},#{successRate},#{verifyTime})")
    void insert(VerifyResult verifyResult);

    //往verifyresultimg表中添加数据
    @Select("insert into verifyresultimg (VerifyResultID,fileName,verifyResult,defectID,brandID) values (#{VerifyResultID},#{fileName},#{verifyResult},#{defectID},#{brandID})")
    void insertImg(VerifyResultImg verifyResultImg);

    //获取所有不同machineID的最新验证结果,每个machineID只获取最新的一条数据
    @Select("select * from verifyresult where ID in (select max(ID) from verifyresult group by machineID)")
    public List<VerifyResult> getAllNewest();

    //获取verifyresult表里最大的id
    @Select("select max(ID) from verifyresult")
    public Integer findMaxID();
}
